namespace DotNetNuke.NavigationControl
{
    using DotNetNuke.Modules.NavigationProvider;
    using DotNetNuke.UI.WebControls;
    using Microsoft.VisualBasic;
    using System;
    using System.Collections;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class DNNDropDownNavigationProvider : DotNetNuke.Modules.NavigationProvider.NavigationProvider
    {
        private DropDownList m_objDropDown;
        private string m_strControlID;

        public override void Bind(DNNNodeCollection objNodes)
        {
            IEnumerator refObjectHelperL0=null;
            try
            {
                refObjectHelperL0 = objNodes.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    DNNNode objNode = (DNNNode) refObjectHelperL0.Current;
                    if (objNode.ClickAction == eClickAction.PostBack)
                    {
                        this.DropDown.AutoPostBack = true;
                    }
                    string strLevelPrefix = Strings.Space(objNode.Level).Replace(" ", "_");
                    if (objNode.IsBreak)
                    {
                        this.DropDown.Items.Add("-------------------");
                    }
                    else
                    {
                        this.DropDown.Items.Add(new ListItem(strLevelPrefix + objNode.Text, objNode.ID));
                    }
                    this.Bind(objNode.DNNNodes);
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
        }

        private void DropDown_SelectedIndexChanged(object source, EventArgs e)
        {
            if (this.DropDown.SelectedIndex > -1)
            {
                base.RaiseEvent_NodeClick(this.DropDown.SelectedItem.Value);
            }
        }

        public override void Initialize()
        {
            this.m_objDropDown = new DropDownList();
            this.DropDown.ID = this.m_strControlID;
            this.DropDown.SelectedIndexChanged += new EventHandler(this.DropDown_SelectedIndexChanged);
        }

        public override string ControlID
        {
            get
            {
                return this.m_strControlID;
            }
            set
            {
                this.m_strControlID = value;
            }
        }

        public override string CSSControl
        {
            get
            {
                return this.DropDown.CssClass;
            }
            set
            {
                this.DropDown.CssClass = value;
            }
        }

        public DropDownList DropDown
        {
            get
            {
                return this.m_objDropDown;
            }
        }

        public override Control NavigationControl
        {
            get
            {
                return this.DropDown;
            }
        }

        public override bool SupportsPopulateOnDemand
        {
            get
            {
                return false;
            }
        }
    }
}

